package com.magina.antiPro.controller;

import com.magina.antiPro.util.NumberMathUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping(value = "/testUtil")
@Slf4j
public class TestUtilController {

    @GetMapping(value = "/testDecimalFormat")
    public String testDecimalFormat(){
        BigDecimal num = new BigDecimal("0.1234788");
        BigDecimal numElse = new BigDecimal("0.4234234234");
        BigDecimal num1 = num.divide(numElse,2,BigDecimal.ROUND_HALF_UP);//除法
        log.info("除法----" + num1);
        BigDecimal mum2 = num.multiply(numElse);
        BigDecimal mum3 = num.multiply(numElse).setScale(4,BigDecimal.ROUND_HALF_UP);
        log.info("乘法----" + mum2);
        log.info("乘法保留小数位----" + mum3);
        return NumberMathUtil.decimalFormat.format(num);
        //12.34%
    }

    @GetMapping(value = "/testToFloatMath")
    public String testToFloatMath(){
        Float num = 0.1283198f;
        return NumberMathUtil.ToFloatMath(num).toString();
        //12.83
    }
}
